package userrepository

import (
	"time"
	ds "zzxq/common/datasource"
	"zzxq/models"
	"zzxq/tools"
)

type DBUser struct {
}

//登录获取用户信息，如果不存在将创建用户信息
func (a *DBUser) UserLogin(phone string) *models.User {
	var user models.User

	ds.GetDb().Where("phone = ?", phone).Attrs(
			models.User{
				Nickname: tools.GetFullName(),
				Phone: phone,
				Avatar: tools.GetAvatar(), 
				Ctime: time.Now().Format("2006-01-02 15:04:05"),
				Utime: time.Now().Format("2006-01-02 15:04:05"),
			}).FirstOrCreate(&user)

	return &user
}

//根据uid获取用户信息
func (a *DBUser) GetUserInfo(uid int) models.User {
	var user models.User

	ds.GetDb().First(&user, uid)

	return user
}
